#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=420;

int arr[N];
int s[N];
int f[N][N],g[N][N];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
		arr[i+n]=arr[i];
	}	
	for(int i=1;i<=2*n;i++)
		s[i]=s[i-1]+arr[i];
	
	memset(f,0x3f3f3f3f,sizeof(f));
	memset(g,0,sizeof(g));
	for(int len=1;len<=n;len++)
	{
		for(int i=1;i+len-1<=2*n;i++)
		{
			int j=i+len-1;
			if(len==1)
			{
				f[i][i]=0;
				g[i][i]=0;
			}
			else{
				for(int k=i;k<j;k++)
				{
					f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]+s[j]-s[i-1]);
					g[i][j]=max(g[i][j],g[i][k]+g[k+1][j]+s[j]-s[i-1]);
				}	
			}
		}
	}
	int maxn=0,minn=0x3f3f3f;
	for(int i=1;i<=n+1;i++)
	{
		maxn=max(maxn,g[i][i+n-1]);
		minn=min(minn,f[i][i+n-1]);		
	}
	
	cout<<minn<<endl;
	cout<<maxn<<endl;

	return 0;
}
